$(function () {
    let pattern = /^((0\.\d{1,2})|([1-9]\d*\.\d{1,2})|([1-9]+\d*)|0)$/

    $(".form-table-money,.form-table-jxPay,.form-table-ccSubsidy,.form-table-jbSubsidy").on("blur",function () {
        let val = $(this).val();
        if (pattern.test(val)==false){
            alert("格式有误！")
            $(this).val("")
        }
    })
})


function butt() {
    let b = confirm("确定提交？");


    let id = [];
    $(".form-table-id").each(function (i, v) {
        id[i] = $(this).val()
    })

    let lid = [];
    $(".form-table-lid").each(function (i, v) {
        lid[i] = $(this).val()
    })

    let fid = [];
    $(".form-table-fid").each(function (i, v) {
        fid[i] = $(this).val()
    })

    let basePay = [];
    $(".form-table-basePay").each(function (i,v) {
        basePay[i] = $(this).val();
    })
    let jtSubsidy = [];
    $(".form-table-jtSubsidy").each(function (i,v) {
        jtSubsidy[i] = $(this).val();
    })
    let txSubsidy = [];
    $(".form-table-txSubsidy").each(function (i,v) {
        txSubsidy[i] = $(this).val();
    })
    let mealSubsidy = [];
    $(".form-table-mealSubsidy").each(function (i,v) {
        mealSubsidy[i] = $(this).val();
    })
    let zfSubsidy = [];
    $(".form-table-zfSubsidy").each(function (i,v) {
        zfSubsidy[i] = $(this).val();
    })

    let jxPay =[]
    $(".form-table-jxPay").each(function (i,v) {
        jxPay[i] = $(this).val()
    })
    let ccSubsidy = []
    $(".form-table-ccSubsidy").each(function (i, v) {
        ccSubsidy[i] = $(this).val()
    })
    let jbSubsidy = []
    $(".form-table-jbSubsidy").each(function (i, v) {
        jbSubsidy[i] = $(this).val()
    })
    let money = []
    $(".form-table-money").each(function (i, v) {
        money[i] = $(this).val()

    })

    if (b == true) {
        for (var i = 0; i <= id.length; i++) {
            let json = {
                id: id[i],
                lid: lid[i],
                fid: fid[i],
                jxPay:jxPay[i],
                // dcoder:dcoder[i],
                // name:name[i],
                // basePay:basePay[i],
                // jtSubsidy:jtSubsidy[i],
                // txSubsidy:txSubsidy[i],
                // mealSubsidy:mealSubsidy[i],
                // zfSubsidy:zfSubsidy[i],
                ccSubsidy: ccSubsidy[i],
                jbSubsidy: jbSubsidy[i],
                money: money[i]
            }
            let basePayElement = parseInt(basePay[i]);
            let jtSubsidyElement = parseInt(jtSubsidy[i]);
            let txSubsidyElement = parseInt(txSubsidy[i]);
            let mealSubsidyElement = parseInt(mealSubsidy[i]);
            let zfSubsidyElement = parseInt(zfSubsidy[i]);
            let jxPayElement = parseInt(jxPay[i]);
            let ccSubsidyElement = parseInt(ccSubsidy[i]);
            let jbSubsidyElement = parseInt(jbSubsidy[i]);
            let moneyElement = parseInt(money[i]);
            let temp = basePayElement+jtSubsidyElement+txSubsidyElement+mealSubsidyElement+zfSubsidyElement+jxPayElement+ccSubsidyElement+jbSubsidyElement+moneyElement

            let sum = temp;

            //console.log(json)
            $.post("/xc/update", json, function (data) {
            })
        }
        alert("提交成功！")
        let jsonA = {
            pid: fid[0],
            id: lid[0]
        }
        $.ajaxSettings.async = false
        $.post("/xc/update2", jsonA, function (i, v) {

        })
        $.ajaxSettings.async = true
        location.href = "/xc/detail/" + fid[0];
        //window. history. go(-1);
    }
}

function fan() {
    window.history.go(-1);
}

$("input").on("blur", function () {
    let pi = /^[1-9][0-9]*([\.][0-9]{1,2})?$/
    let li = $(this).val();
    if (!pi.test(li)) {
        alert("格式不正确！")
    }

});